<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
.box{
        width:100px;
        height: 100px;
        margin: 100px;
        background-color: aqua;
    }
    </style>
</head>
<body>
    <div class="box">

    </div>
    <script>
        var box = document.querySelector(".box")
        box.addEventListener("mousemove",function(e){
            //思路：获取鼠标移动在页面上的x,y轴的距离，然后再减去盒子的offsetLeft和offsetTop值 即可获得鼠标在盒子中移动时候的坐标
            var x = e.pageX - this.offsetLeft;
            var y = e.pageY - this.offsetTop;
            this.innerHTML = "鼠标的x坐标为" + x + ";y坐标为" + y;
        })
    </script>
</body>
</html>